// pages/mine/mine.js
var api = require("../../utils/api")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentab: 0,
    userInfo: {},
    hasUserInfo: false

  },
  clicktab1() {
    this.setData({
      currentab: 0
    })
    this.getMainRecord(this.data.user.id)
  },
  clicktab2() {
    this.setData({
      currentab: 1
    })
  },

  clicktab3() {
    this.setData({
      currentab: 2
    })
    this.getMainLike(this.data.user.id)
  },
  clicktab4() {
    this.setData({
      currentab: 3
    })
  },
  clicktab5() {
    this.setData({
      currentab: 4
    })
  },
  gotoPage(t) {
    var cid = t.currentTarget.dataset.id;
    console.log("----" + cid)
    wx.navigateTo({
      url: "/pages/index/index?cid=" + cid
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
      that.getMainRecord(that.data.user.id)
  },
  getMainLike: function (userId) {
    const that = this;
    const params = {
      userId: userId
    }

    wx.request({
      url: api.getMainLike,
      method: "POST",
      data: params,
      success(res) {
        console.log(res.data)
        that.setData({
          likes: res.data.data
        })

      }
    })

  },
  getMainRecord: function (userId) {
    const that = this;
    const params = {
      userId: userId
    }

    wx.request({
      url: api.getMainRecord,
      method: "POST",
      data: params,
      success(res) {
        console.log(res.data)
        that.setData({
          records: res.data.data
        })

      }
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})